//
//  LBWStatus.swift
//  weibo
//
//  Created by Limonwei on 15/12/9.
//  Copyright © 2015年 heima. All rights reserved.
//
//微博首页内容的模型

import UIKit

class LBWStatus: NSObject {
    
    //微博的内容
    var text: String?
    
    // 当前微博作者信息
    var user: LBWUser?
    
    // 微博的创建时间
    var created_at: String?
    
    // 来自
    var source: String?
    
    // 转发
    var reposts_count: Int = 0
    
    // 评论数
    var comments_count: Int = 0
    
    // 表态数
    var attitudes_count: Int = 0
    
    // 转发微博的内容
    var retweeted_status: LBWStatus?
    
    //微博id
    var id: Int64 = 0
    
    //微博的配图
    var pic_urls: [LBWStatusPictureInfo]?
    
    //KVC构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        
        //遍历字典,用setValue:forKey给对象的属性赋值
        setValuesForKeysWithDictionary(dict)
    }
    
    //KVC
    override func setValue(value: AnyObject?, forKey key: String) {
     
        if key == "user" {
            
            if let dict = value as? [String: AnyObject] {
                user = LBWUser(dict: dict)
            }
        }else if key == "retweeted_status" {
            if let dict = value as? [String: AnyObject] {
                retweeted_status = LBWStatus(dict: dict)
            }
        }else if key == "pic_urls" {
            
            //判断当前value是否是一个字典数组
            if let array = value as? [[String: AnyObject]] {
                
                //定义临时的数组集合
                var tempArray = [LBWStatusPictureInfo]()
                
                //遍历数组
                for dict in array {
                    
                    //字典转模型
                    tempArray.append(LBWStatusPictureInfo(dict: dict))
                }
                pic_urls = tempArray
                
            }
            
        }else {
            super.setValue(value, forKey: key)
            
        }
    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
 
    }
    
    //重写description方法
    override var description: String {
        
        //传入一键数组
        let keys = ["text", "retweeted_status"]
        
        //找这个键对应的value,并生成一个字典
        return dictionaryWithValuesForKeys(keys).description
    }


}






















